import java.util.Arrays;

public class Matrix {
    private  int array1 [][] ;

    public Matrix(int array[][]) {

        this. array1= array;
    }


    private static int[][] createMatrix(int m, int n, int arr[][] ){

        int[][] array = new int[m][n];
        arr=array;

        for (int i =0; i<m; i++){
            for(int j =0; j<n; j++){
                array[i][j] =   (int)(Math.random()*5);
               System.out.print(array [i][j]+ " ");
            }
            System.out.println();
        }
     return array;
    }

    private static void sum(int m, int n){



    }


    private boolean canBeMultiplied(int arr1[][], int arr2[][]){
          int arr1Col = arr1[0].length;
        int arr2Row =arr2.length;
        if(arr1Col==arr2Row){
            return true;
        }else return false;

    }

    private static int[][] multiplyWith(int arr[][], int arr2[][]){
        int row = arr.length;
        int columns = arr2[0].length;

        int Col = arr[0].length;
        int Row = arr2.length;

        if(Col!=Row){
          throw new IllegalArgumentException("Can not multiply 2 matrix");
        }
        int [][]res = new int [row][columns];

        for (int i = 0; i < row-1; i++)
            for (int j = 0; j < columns; j++)

                for(int k = 0; k < Col; k++){
                    res[i][j] +=arr[i][k] *arr2[k][j];
                }

                    //res[i][j] = arr[i][j] * arr2[j][i];

       return res;
    }





    private static void transpose(){

    }

    private static void print(int[][]arr, String label){

           int  row = arr.length;
        int columns = arr[0].length;

        System.out.println(label);
        for(int i =0; i<row; i++) {
            for(int j=0; j<columns; j++) {
                System.out.print(arr[i][j] + " ");

            }
            System.out.println();
        }
    }


    public static void main(String[] args) {
//          int array1[][]=null;
//        int array2[][] = null;
        int array1[][] ={{4, 9}, {8, 7}, {3, 2}, {9, 1}};
        int array2[][] = {{4, 11, 12, 14}, {13, 9, 22, 7}};

        int [][]z = multiplyWith(array1,array2);
        print(array1,"Matrix1 : ");
        print(array2," multiplied by Matrix2 : ");
        print(z, "result");












    }
}
